package com.cx.algrithm.queue.common;

public class ArrayQueue{

    private int maxSize; // 数组最大容量
    private int front;//队列头
    private int rear;//队列尾
    private int[] arr; //队列存放

    public ArrayQueue(int arrMaxSize){
        maxSize = arrMaxSize;
        arr = new int[maxSize];
        front = -1;
        rear= -1;
    }

    public boolean isFull(){
        return rear == maxSize -1;
    }

    public boolean isEmpty(){
        return rear == front;
    }

    public void addQueue(int n){

        if(isFull()){
            System.out.println("队列满了");
            return;
        }
        rear++;
        arr[rear] = n;
    }

    public int getQueue(){
        if(isEmpty()){
            throw new RuntimeException("队列空");
        }
        front++;
        return arr[front];
    }

    public void showQueue(){
        if(isEmpty()){
            System.out.println("队列空");
            return;
        }
        for(int i=0;i<arr.length;i++){
            System.out.printf("arr[%d]=%d\n",i,arr[i]);
        }
    }
}
